package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.user.IVerifyService;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.UserVerifyRequest;
import com.mall.user.dto.UserVerifyResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName VerifyController
 * @Description 用户注册激活功能
 * @Author fan
 * @Date 2021/5/22 14:36
 **/

@RestController
@RequestMapping("/user")
public class VerifyController {

    @Reference(timeout = 3000,check = false)
    IVerifyService iVerifyService;

    @GetMapping("/verify")
    @Anoymous
    public ResponseData verify(@RequestParam Map<String,String> map){
        String uid = (String) map.get("uid");
        String username = (String) map.get("username");
        UserVerifyRequest userVerifyRequest = new UserVerifyRequest();
        userVerifyRequest.setUserName(username);
        userVerifyRequest.setUuid(uid);
        UserVerifyResponse userVerifyResponse=iVerifyService.verify(userVerifyRequest);
        if (userVerifyResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            ResponseData responseData = new ResponseUtil<>().setData(null, SysRetCodeConstants.SUCCESS.getMessage());
            return responseData;
        }
        return new ResponseUtil<>().setErrorMsg(userVerifyResponse.getMsg());
    }

}
